﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;
using Hockey.Shared;

namespace Hockey.UILayer.ViewModels
{
    /// <summary>
    /// EndGame Notification Form ViewModel
    /// </summary>
    public class EndGameFormVM: NotificationObject
    {
        private IEventAggregator _events;
        private string _playerName;

        /// <summary>
        /// Constructor
        /// </summary>
        public EndGameFormVM(IEventAggregator events)
        {
            if (events == null)
                throw new ArgumentNullException("Events");
            _events = events;

            // create commands
            CloseCommand = new AutoDelegateCommand(() => { CloseForm(); });
        }

        /// <summary>
        /// Property for setting player name
        /// </summary>
        public string PlayerName
        {
            private get
            {
                return _playerName;
            }
            set
            {
                _playerName = value;
                CreateTitle();
            }
        }

        /// <summary>
        /// Binding property for text in the view
        /// </summary>
        public string Title
        { get; set; }

        /// <summary>
        /// Close command
        /// </summary>
        public AutoDelegateCommand CloseCommand
        { get; set; }

        
        /// <summary>
        /// Creates the text displayed in the view
        /// </summary>
        private void CreateTitle()
        {
            Title = "Vyhrál hráč: " + _playerName;
            RaisePropertyChanged("Title");
        }

        /// <summary>
        /// Closes the form
        /// </summary>
        private void CloseForm()
        {
            _events.GetEvent<CloseForm>().Publish(this);
        }

    }
}
